% plot the human mean data band 
% desired outputs 
function MeanValue_G(ave_time,upperB,lowerB,x_mean,name,...
    ylabelstr,outputIndex,LineNumber)
% figure('Visible','Off');
figure;
% ha = area(ave_time, [lowerB; upperB-lowerB]','FaceColor',[.8 0.8 0.8]);
% set(ha(1), 'FaceColor', 'none') % this makes the bottom area invisible
% set(ha, 'LineStyle', 'none')
hold on
apc3 = 0.775000000000000*0.7;
apc4 = 0.690000000000000*0.7;
apc = [0.100000000000000   0.2000000000000   apc3   apc4];
% apc = [0.100000000000000   0.2000000000000   0.775000000000000   0.690000000000000];
% pp1 = plot(ave_time,upperB,'b.-'); hold on; pp2 = plot(ave_time,lowerB,'b.-');
% pp3 =plot(ave_time,x_mean,'r.-');
% pp1 = plot(ave_time,upperB,'k--',ave_time,lowerB,'k--',...
%     ave_time,x_mean,'k')


%%%%%%%%%%%% error band %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % E =abs(upperB - x_mean);%
% % % E= std(x_mean)*ones(size(ave_time));
% % pp1 = errorbar(ave_time(1:4:end),x_mean(1:4:end),E(1:4:end),'ro');
%%%%%%%%%%% grey region %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ha = area(ave_time, [lowerB; upperB-lowerB]','FaceColor',[.8 0.8 0.8]);
% ha = area(ave_time, [lowerB; upperB]','FaceColor',[.8 0.8 0.8]);
% size(ha)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ha = area(ave_time, [lowerB; upperB-lowerB]');
% set(ha(1),'FaceColor','none')
% set(ha(1),'LineStyle','none')
% set(ha(2),'FaceColor',[.8 0.8 0.8])
% set(ha(2),'EdgeColor',[.4 0.4 0.4],...
%                'LineWidth',2,'LineStyle','--')
% legend(harea(2),'red')


set(ha(1), 'FaceColor', 'none') % this makes the bottom area invisible
set(ha, 'LineStyle', 'none')
pp0 = plot(ave_time,upperB,'--',ave_time,lowerB,'--');
set(pp0,'Color',[0.4 0.4 0.4])
% size(pp0)
hold on;
pp2 = plot(ave_time(1:4:end),x_mean(1:4:end),'ko');  


% if funcIndex == 2
%     % fit to cannonical function
%        pp2 = plot(ave_time(1:4:end),x_mean(1:4:end),'ko',ave_time,yd_can(ns_time,a),'r');  
%        R = corrcoef(x_mean, yd_can(ns_time,a));
%        R(1,2)
% else
%     % fit to linear function
%        pp2 = plot(ave_time(1:4:end),x_mean(1:4:end),'ko',ave_time,yd_L(ns_time,a),'r');
%        R = corrcoef(x_mean, yd_L(ns_time,a));
%        R(1,2)
% end



% set(pp1                            , ...
%   'LineWidth'       , 2           , ...
%   'Marker'          , 'o'         , ...
%   'MarkerSize'      , 6           , ...
%   'MarkerEdgeColor' , 'r'  , ...
%   'MarkerFaceColor' , [1 1 1]  );


% ylim([-1.4,1.4]);
xlim([0 1]);
% if strcmp(name,'SKnee.eps')
%     ylim([0 1.5])
% end
set(pp0,'MarkerSize', 10,'LineWidth',2);
% set(pp1,'MarkerSize', 10,'LineWidth',2);
set(pp2,'MarkerSize', 10,'LineWidth',3);
set(gca,'position',apc);
% meanValuePlot(ave_timeLNS,upperBLNS,lowerBLNS,x_meanLNS);
xlabel({'Scaled Time'},'Interpreter','LaTex','FontSize',20)
ylabel({ylabelstr},'Interpreter','LaTex','FontSize',20)
% ylim(ylimit);
% legend('upperbound','lowerbound','mean') %,'robot data'
set(gca,'FontSize',16)
switch outputIndex
    case 1 % hip position
    l=legend(pp2, {'$p^H_{hip}$ ','$p_{hip}^{d}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 2 % linearized hip position
        l=legend(pp2,{'$\delta p^{H}_{hip}$','$\delta p_{hip}^{d}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 3 % non-stance slope
        l=legend(pp2,{'$m^{H}_{nsl}$','$m_{nsl}^{d}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 4 % linearized non-stance slope
        l=legend(pp2,{'$\delta m^{H}_{nsl} $','$\delta m_{nsl}^{d}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 5 % hip angle
        l=legend(pp2,{'$\theta^{H}_{hip}$','$\theta_{hip}^{d}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 6 % stance knee angle
        ylim([0 0.8])
        l=legend(pp2,{'$\theta^{H}_{sk}$','$\theta_{sk}^{d}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 7 % non-stance knee angle
        l=legend(pp2,{'$\theta^{H}_{nsk}$','$\theta_{nsk}^{d}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 8 % torso hip angle
        ylim([-0.2 0.4])
        l=legend(pp2,{'$\theta^{H}_{torso}$','$\theta_{torso}^{d}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 9 % stance COM slope
        ylim([-0.5 0.5])
         l=legend(pp2,{'$m^{H}_{stCOM}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
    case 10 % linearized stance COM slope
        ylim([-0.5 0.5])
         l=legend(pp2,{'$\delta m^{H}_{stCOM}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);

    case 11 % non-stance COM slope
        ylim([-0.5 0.8])
         l=legend(pp2,{'$m^{H}_{nsCOM}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);

    case 12 % linearized non-stance COM slope
         ylim([-0.5 0.8])
         l=legend(pp2,{'$\delta m^{H}_{nstCOM}$'},1, ...
   'Location', 'BestOutside', 'Orientation','horizontal',...
   'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
% % %     case 9 % theta4
% % %         l=legend(pp2,{'$\theta^{H}_{4}$','$\theta_{4}^{d}$'},1, ...
% % %    'Location', 'BestOutside', 'Orientation','horizontal',...
% % %    'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
% % %     case 10 % ns_torso_slope
% % %                 l=legend(pp2,{'$m^{H}_{nstorso}$','$m_{nstorso}^{d}$'},1, ...
% % %    'Location', 'BestOutside', 'Orientation','horizontal',...
% % %    'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
% % %     case 11 % linearized ns_torso_slope
% % %                 l=legend(pp2,{'$\delta m^{H}_{nstorso}$','$\delta m_{nstorso}^{d}$'},1, ...
% % %    'Location', 'BestOutside', 'Orientation','horizontal',...
% % %    'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
% % %     case 12 % stance torso slope
% % %                 l=legend(pp2,{'$m^{H}_{storso}$','$m_{storso}^{d}$'},1, ...
% % %    'Location', 'BestOutside', 'Orientation','horizontal',...
% % %    'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
% % %     case 13 % linearized torso slope
% % %                 l=legend(pp2,{'$\delta m_{storso}^{H}$','$\delta m_{storso}^{d}$'},1, ...
% % %    'Location', 'BestOutside', 'Orientation','horizontal',...
% % %    'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
% % %     case 14 % COM
% % %                 l=legend(pp2,{'$COM^{H}$','$COM^{d}$'},1, ...
% % %    'Location', 'BestOutside', 'Orientation','horizontal',...
% % %    'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
% % %         
% % %     case 15 % linearized COM
% % %                 l=legend(pp2,{'$\delta COM^{H}$','$\delta COM^{d}$'},1, ...
% % %    'Location', 'BestOutside', 'Orientation','horizontal',...
% % %    'Interpreter','LaTeX','LineWidth',3,'FontSize',20);
end

p = get(l,'position');
% set(l,'Box','off');
set(l, 'position', [0 p(2)-.2 1-0.2 p(4)], 'Box','off');
outputtype = num2str(LineNumber);
print(gcf, '-depsc',['./figure/' outputtype name])


function ret = yd_can(t,a)
% function 2
ret = exp(-a(4)*t).*(a(1)*cos(a(2)*t)+a(3)*sin(a(2)*t))+a(5);

end

function ret = yd_L(t,a)
    % function 1
        ret = a(1)*t;%+a(1,5)
end

end
